package com.czb.seckill.util;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author: 陈正彬
 */
public class MD5Util {

    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    //准备应该salt
    public static final String SALT = "4tIY5VcX";

    //加密加salt，完成 MD5(password + salt)
    public static String inputPassToMidPass(String inputPass) {
        String str = SALT.charAt(0) + inputPass +SALT.charAt(6);
        return md5(str);
    }

    //加密加salt，把MidPass转成DB中的密码
    public static String midPassToDBPass(String midPass,String salt) {
        String str = salt.charAt(1) + midPass + salt.charAt(5);
        return md5(str);
    }

    //将password，直接转为DB中的密码
    public static String inputPassToDBPass(String inputPass,String salt) {
        String midPass = inputPassToMidPass(inputPass);
        String dbPass = midPassToDBPass(midPass , salt);
        return dbPass;

    }
}
